package com.ruoyi.tel.controller;

import java.util.List;

import com.ruoyi.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tel.domain.TelInfo;
import com.ruoyi.tel.service.ITelInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 电话号码信息Controller
 * 
 * @author dgjunjie
 * @date 2021-04-10
 */
@Controller
@RequestMapping("/tel/info")
public class TelInfoController extends BaseController
{
    private String prefix = "tel/info";

    @Autowired
    private ITelInfoService telInfoService;

    @RequiresPermissions("tel:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询电话号码信息列表
     */
    @RequiresPermissions("tel:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TelInfo telInfo)
    {
        startPage();
        List<TelInfo> list = telInfoService.selectTelInfoList(telInfo);
        return getDataTable(list);
    }



    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<TelInfo> util = new ExcelUtil<TelInfo>(TelInfo.class);
        List<TelInfo> userList = util.importExcel(file.getInputStream());
        String operName = ShiroUtils.getSysUser().getLoginName();
//        String message = telInfoService.importTel(userList, updateSupport, operName);
//        return AjaxResult.success(message);
        return AjaxResult.success("");
    }


    /**
     * 导出电话号码信息列表
     */
    @RequiresPermissions("tel:info:export")
    @Log(title = "电话号码信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TelInfo telInfo)
    {
        List<TelInfo> list = telInfoService.selectTelInfoList(telInfo);
        ExcelUtil<TelInfo> util = new ExcelUtil<TelInfo>(TelInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 新增电话号码信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存电话号码信息
     */
    @RequiresPermissions("tel:info:add")
    @Log(title = "电话号码信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TelInfo telInfo)
    {
        return toAjax(telInfoService.insertTelInfo(telInfo));
    }

    /**
     * 修改电话号码信息
     */
    @GetMapping("/edit/{telId}")
    public String edit(@PathVariable("telId") Long telId, ModelMap mmap)
    {
        TelInfo telInfo = telInfoService.selectTelInfoById(telId);
        mmap.put("telInfo", telInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存电话号码信息
     */
    @RequiresPermissions("tel:info:edit")
    @Log(title = "电话号码信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TelInfo telInfo)
    {
        return toAjax(telInfoService.updateTelInfo(telInfo));
    }

    /**
     * 删除电话号码信息
     */
    @RequiresPermissions("tel:info:remove")
    @Log(title = "电话号码信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(telInfoService.deleteTelInfoByIds(ids));
    }
}
